# 开始的解法：还出错在忽略掉题的条件就是可以多次取反同一个元素
class Solution:
    def largestSumAfterKNegations(self, A: List[int], K: int) -> int:

        for i in range(K):
            tmp = A.index(min(A))
            A[tmp] = -A[tmp]
        return sum(A)

# 进阶的改进方法：涉及到最大最小可以试着先排序
class Solution:
    def largestSumAfterKNegations(self, A: List[int], K: int) -> int:
        heapq.heapify(A)
        for  i in range(K):
            tmp = heapq.heappop(A)
            if tmp >= 0:
                heapq.heappush(A, tmp * (-1)^(K-i))
                break
            else:
                heapq.heappush(A, -tmp)
        return sum(A)